package myservlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import dao.User;

import utils.DbAccess;


public class Users extends HttpServlet {

	DbAccess db = null;
	

	public void doGet(HttpServletRequest req, HttpServletResponse resp)
		throws ServletException, IOException {
		proccess(req, resp);
	}
	
	public void doPost(HttpServletRequest req, HttpServletResponse resp)
		throws ServletException, IOException {
		proccess(req, resp);
	}
	
	private void proccess(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException {
		req.setCharacterEncoding("UTF-8");
		res.setCharacterEncoding("UTF-8");
		res.setContentType("text/xml");
		String userId = null;
		Connection conn = null;
		try{
			conn = db.getConn();
			String userInfor = new User().getUserInfoFromDb(userId, conn);
			PrintWriter out = res.getWriter();
		     out.println("<h1>" + userInfor + "</h1>");
		}catch (Exception e) {
			e.printStackTrace();
		}finally{
			if(conn!=null){try{conn.close();}catch (Exception e) {
			}}
		}
	}
}

